package com.design.observer.service.impl;

import com.design.observer.service.DisplayElement;
import com.design.observer.service.Observer;
import com.design.observer.service.Subject;

/**
 * @author zhengzihong
 * @version 1.0.0
 * @date 2018/9/8
 * @Description
 */
public class CurrentConditionDisplay implements DisplayElement,Observer {

    private float temperature;

    private float humidity;

    private Subject weatherData;

    /**
     * 注册成为观察者
     * @param weatherData
     */
    public CurrentConditionDisplay(Subject weatherData){
        this.weatherData = weatherData;
        weatherData.registerObserver(this);
    }

    /**
     * 展示数据
     */
    @Override
    public void display() {
        System.out.println("Current conditions:"+ temperature+"F degrees and "+humidity+"% humidity");
    }

    /**
     * 更新数据
     * @param temp
     * @param humidity
     * @param pressure
     */
    @Override
    public void update(float temp, float humidity, float pressure) {
        this.humidity = humidity;
        this.temperature = pressure;
        display();
    }
}
